package com.hd.crdao.adapter;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.MyApplication;
import com.hd.crdao.base.MyBaseAdapter;
import com.hd.crdao.bean.DomainNameBean;

import java.util.List;

/**
 *
 *@author Administrator
 *@date 2017/7/3 0003
 */
public class DomainNaneAdapter extends MyBaseAdapter<DomainNameBean.RowsBean> {

    public DomainNaneAdapter(List<DomainNameBean.RowsBean> dataSets) {
        super(dataSets);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(MyApplication.getContext(), R.layout.item_domain, null);
            //找到控件
            holder.mDomainName = (TextView) convertView.findViewById(R.id.domain_name);
            holder.mPrice = (TextView) convertView.findViewById(R.id.price_domain);
            holder.mStatus = (TextView) convertView.findViewById(R.id.status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        DomainNameBean.RowsBean rowsBean = mDataSets.get(position);
        String domainState = rowsBean.getDomainState();

        //设置数据
        holder.mDomainName.setText(rowsBean.getDomainName());
        holder.mPrice.setText("￥"+rowsBean.getDomainPrice());
        if(TextUtils.equals("0",domainState)){
            holder.mStatus.setText("立即购买");
        }else if(TextUtils.equals("3",domainState)){
            holder.mStatus.setText("待付款");
        }else if(TextUtils.equals("5",domainState)){
            holder.mStatus.setText("已被注册");
        }else if(TextUtils.equals("7",domainState)){
            holder.mStatus.setText("已过期");
        }

        return convertView;
    }

    class ViewHolder {
        TextView mDomainName;
        TextView mPrice;
        TextView mStatus;
    }
}
